//
//  DMRewardedVideoManager.h
//  DualMediationSDK
//
//  Created by YeJary on 2025/7/9.
//

#import <Foundation/Foundation.h>
#import "DMAdDelegate.h"

NS_ASSUME_NONNULL_BEGIN

@interface DMRewardedVideoManager : NSObject

+ (instancetype)shareRewardedVideoManager;
@property (nonatomic, weak) id<DMAdDelegate> delegate;

- (void)irDelegate;

- (void)showIrSourceRV;

// 双广告位支持属性
@property (nonatomic, assign) BOOL isDualAdEnabled;
@property (nonatomic, strong) NSString *currentPrimaryAdUnitId;
@property (nonatomic, strong) NSString *currentSecondaryAdUnitId;
@property (nonatomic, assign) BOOL isPrimaryAdLoaded;
@property (nonatomic, assign) BOOL isSecondaryAdLoaded;
@property (nonatomic, assign) NSTimeInterval primaryAdLoadTime;
@property (nonatomic, assign) NSTimeInterval secondaryAdLoadTime;
@property (nonatomic, assign) double primaryAdECPM;
@property (nonatomic, assign) double secondaryAdECPM;

// 重试机制相关属性
@property (nonatomic, assign) NSInteger retryCount;           // 当前重试次数
@property (nonatomic, assign) NSInteger maxRetryCount;        // 最大重试次数
@property (nonatomic, assign) NSTimeInterval baseRetryInterval; // 基础重试间隔（秒）
@property (nonatomic, assign) NSInteger totalFailureCount;    // 总失败次数
@property (nonatomic, assign) NSInteger totalLoadAttempts;    // 总加载尝试次数
@property (nonatomic, assign) NSTimeInterval lastRetryTime;   // 上次重试时间
@property (nonatomic, assign) BOOL isRetryPaused;            // 是否暂停重试
@property (nonatomic, strong) NSTimer *retryTimer;           // 重试定时器

// 场景化激励视频接口
- (void)showIrSourceRVForScene:(NSString *)scene;
- (BOOL)isRewardedVideoReadyForScene:(NSString *)scene;


// 双广告位支持方法
- (void)loadDualRewardedAds;
- (NSString *)selectOptimalAdUnitId;
- (void)switchToSecondaryAdIfNeeded;

// 重试机制相关方法
- (void)initializeRetrySettings;                    // 初始化重试设置
- (void)resetRetryState;                           // 重置重试状态
- (void)scheduleRetryWithDelay:(NSTimeInterval)delay; // 安排延迟重试
- (void)cancelRetryTimer;                          // 取消重试定时器
- (BOOL)shouldRetry;                               // 判断是否应该重试
- (NSTimeInterval)calculateRetryDelay;             // 计算重试延迟时间
- (void)updateFailureStatistics;                  // 更新失败统计
- (double)calculateFailureRate;                    // 计算失败率

@end

NS_ASSUME_NONNULL_END
